<div class="companies index form">
<h2><?php __('Companies');?></h2>

<!-- Search Box -->
<p class="searcher">
    <?php e($form->input('Company.search',
        array('class'=>'input text', 'label'=>false))); ?>
    <?php e($html->link(__('Search Companies', true),
        array('controller'=>'companies', 'action'=>'index'),
        array('class'=>'button submit', 'style'=>'clear:none', 'id'=>'link_search'))); ?>
</p>
<br class="clear"/>

<!-- Table Navigation -->
<div class="tablenav">
    <div class="batchactions"></div>
    <?php echo $this->element('pager'); ?>
</div>

<?php if(count($companies)): ?>
<!-- Table Content Area -->
<table id="table_companies" class="table fixed">
    <thead title="<?php __('Click a column to sort data table'); ?>">
        <tr>
            <th width="2%" class="checkbox" title="<?php __('Click to select/deselect all records'); ?>"><input type="checkbox" class="checkbox" /></th>
            <th width="24%"><?php __('Company Name');?></th>
            <th width="10%"><?php echo $paginator->sort('company_location_id');?></th>
            <th width="18%"><?php echo $paginator->sort('company_industry_id');?></th>
            <th width="10%"><?php echo $paginator->sort('company_type_id');?></th>
            <th width="10%"><?php echo $paginator->sort('job_count');?></th>
            <th width="26%"><?php echo $paginator->sort('created');?></th>
        </tr>
    </thead>
    <tfoot title="<?php __('Click a column to sort data table'); ?>">
        <tr>
            <th class="checkbox" title="<?php __('Click to select/deselect all records'); ?>"><input type="checkbox" class="checkbox" /></th>
            <th><?php __('Company Name');?></th>
            <th><?php echo $paginator->sort('company_location_id');?></th>
            <th><?php echo $paginator->sort('company_industry_id');?></th>
            <th><?php echo $paginator->sort('company_type_id');?></th>
            <th><?php echo $paginator->sort('job_count');?></th>
            <th><?php echo $paginator->sort('created');?></th>
        </tr>
    </tfoot>
    <tbody>
        <?php foreach ($companies as $i=>$company):
            $class = $i++ % 2 == 0 ? ' class="altrow"' : ''; ?>
        <tr<?php echo $class;?>>
            <td class="checkbox"><input type="checkbox" class="checkbox" /></td>
            <!-- Company.name -->
            <td class="name">
                <p class="name">
                    <?php e($html->link($company['Company']['name'],
                        array('action'=>'view', $company['Company']['id']),
                        array('title'=>$company['Company']['name'])
                    )); ?>
                    <?php e($text->autoLink($company['Company']['website'],
                        array(
                            'title'=>__('Click to visit the official website of the company', true),
                            'class'=>'external')
                    )); ?>
                </p>
                <p class="email">
                    <?php echo $text->autoLinkEmails($company['Company']['email'],
                        array('title'=>sprintf(__('Send mail to: %s', true), $company['Company']['name']))); ?>
                </p>
                <p class="modified">
                    <?php __('Modified on'); ?>&nbsp;
                    <?php echo $html->link($time->format($options['longDateFormat'], $company['Company']['modified']),
                        array('modified' => $time->format($options['queryDateFormat'], $company['Company']['modified'])),
                        array('title' => sprintf(__('View companies modified on %s', true), $time->format($options['queryDateFormat'], $company['Company']['created'])))
                    ); ?><br />
                    <?php __('Modified by'); ?>&nbsp;
                    <?php echo $html->link($company['ModifiedUser']['username'],
                        array('modified_by' => $company['ModifiedUser']['username']),
                        array('title' => sprintf(__('View companies modified by %s', true), $company['ModifiedUser']['username']))
                    ); ?>
                </p>
                <?php if($user['group'] != 'student'): ?>
                    <p class="actions">
                        <span class="view">
                            <?php echo $html->link(__('View', true),
                                array('action'=>'view', $company['Company']['id'])); ?>
                        </span>
                        <span class="edit">
                            <?php echo $html->link(__('Edit', true),
                                array('action'=>'edit', $company['Company']['id'])); ?>
                        </span>
                        <span class="delete">
                            <?php echo $html->link(__('Delete', true),
                                array('action'=>'delete', $company['Company']['id'])); ?>
                        </span>
                    </p>
                <?php endif; ?>
            </td>
            <!-- Company.location -->
            <td class="location">
                <p class="location">
                <?php e($html->link($company['CompanyLocation']['name'],
                    array('company_location_id' =>$company['CompanyLocation']['id']),
                    array('title' =>sprintf(__('View company located in %s', true), $company['CompanyLocation']['name'])))); ?>
                </p>
                <p class="counter">
                    <?php printf(__('%s companies in total', true), $company['CompanyType']['company_count']); ?>
                </p>
            </td>
            <!-- Company.industry -->
            <td class="industry">
                <p class="industry">
                <?php echo $html->link($company['CompanyIndustry']['name'],
                    array('company_industry_id'=>$company['CompanyIndustry']['id']),
                    array('title' =>sprintf(__('View company under industry %s', true), $company['CompanyIndustry']['name']))); ?>
                </p>
                <p class="counter">
                    <?php printf(__('%s companies in total', true), $company['CompanyIndustry']['company_count']); ?>
                </p>
            </td>
            <!-- Company.type -->
            <td class="type">
                <p class="type">
                <?php echo $html->link($company['CompanyType']['name'],
                    array('company_type_id'=>$company['CompanyType']['id']),
                    array('title' =>sprintf(__('View company that is %s', true), $company['CompanyType']['name']))); ?>
                </p>
                <p class="counter">
                    <?php printf(__('%s companies in total', true), $company['CompanyType']['company_count']); ?>
                </p>
            </td>
            <!-- Company.job_count -->
            <td class="job_count">
                <?php if($company['Company']['job_count']>0): ?>
                    <p class="job_link">
                        <?php echo $html->link(__('view detail', true),
                            array('controller'=>'jobs','action'=>'viewByCompany',$company['Company']['id']),
                            array('title'=>__('Click to view jobs for this company', true))
                        );?>
                    </p>
                <?php endif; ?>
                <p class="counter">
                    <?php printf(__('%s jobs in total', true), $company['Company']['job_count']); ?>
                </p>
            </td>
            <!-- Company.created -->
            <td class="created">
                <p class="created">
                    <?php __('Created on'); ?>&nbsp;
                    <?php echo $html->link($time->format($options['longDateFormat'], $company['Company']['created']),
                        array('created' => $time->format($options['queryDateFormat'], $company['Company']['created'])),
                        array('title' => sprintf(__('View company added on %s', true), $time->format($options['queryDateFormat'], $company['Company']['created'])))
                    ); ?><br />
                    <?php __('Created By'); ?>&nbsp;
                    <?php echo $html->link($company['CreatedUser']['username'],
                        array('created_by' => $company['CreatedUser']['username']),
                        array('title' => sprintf(__('View companies created by %s', true), $company['CreatedUser']['username']))
                    ); ?>
                </p>
                <p class="clicks">
                    <?php printf(__('Clicks: %d', true), $company['Company']['clicks']); ?>
                </p>
            </td>
        </tr>
        <?php endforeach; ?>
    </tbody>
</table>
<?php else: ?>
    <p><?php __('No company found'); ?></p>
<?php endif; ?>

</div>

<!-- Script for ajax Company deletion -->
<script type="text/javascript">
jQuery(function(){
    /* Observe search button click */
    $('a#link_search').click(function(){
        var value = $('#CompanySearch').fieldValue()[0];
        if(value != ''){
            this.href = this.href + '/index/name:' + value;
        }else{
            return false;
        }
    });
    /* Show hide action links */
    $('tbody tr').hover($.sme.cbk.showActions, $.sme.cbk.hideActions);
    $('table#table_companies p.actions a[href*=delete]').click($.sme.cbk.ajaxDelete);
});
</script>